<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'autoload.php';

use payClass\Datebase;
use payClass\QRcode;
use payClass\pay\Config;

/**
 * 出款
 */
class Payment
{
	public static function paymentDo()
	{
		$db     = new Datebase();

		$config = new Config();

		$param  = $db->param();

		// 数据检测
		$verifyRes = $db->verifyDraw($param);

		if ($verifyRes != 1) exit($verifyRes);

		$data = [
			'order_num' => $param['order'],
			'account'   => $param['account_Name'],
			'name'      => $param['account_Number'],
			'money'     => sprintf("%.2f", $param['amount']),
		];
		$data['sign'] = Config::encrypt($data);
		// 请求头信息
		$header = [
			'Authorization: Bearer '.Config::$token
		];

		$curlRes = Config::setHttpRequest(Config::$api . '/api/to_alipay', $data, 'POST', $header);

		$resArray = json_decode($curlRes, true);

		if ($resArray['code'] != '0') $db->ajaxReturn($resArray['msg']);

		$db->ajaxReturn($resArray['提交成功']);
	}
}

Payment::paymentDo();
